package com.rabc.utils;

import com.rabc.framework.web.domain.LoginUserDetails;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtils {
    /**
     * 获取当前登录的UserDetails对象
     * @return 当前登录的UserDetails，如果没有登录则返回null
     */
    public static LoginUserDetails getCurrentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() instanceof UserDetails) {
            return (LoginUserDetails) authentication.getPrincipal();
        }
        return null;
    }

}
